package org.boot.ssm.wxshop.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.boot.ssm.wxshop.common.impl.BaseServiceImpl;
import org.boot.ssm.wxshop.domain.Goods;
import org.boot.ssm.wxshop.mapper.GoodsMapper;
import org.boot.ssm.wxshop.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsServiceImpl extends BaseServiceImpl<Goods> implements GoodsService {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public PageInfo<Goods> queryPageListByParamPlus(Integer pageNo, Integer pageSize, Goods goods, String orderBy,Integer order) {
        PageHelper.startPage(pageNo,pageSize);
        PageInfo<Goods> pageInfo = new PageInfo<>(goodsMapper.queryListByParamPlus(goods,orderBy,order));
        return pageInfo;
    }

    @Override
    public List<Goods> queryListByParamPlus(Goods goods, String orderBy,Integer order) {
        return goodsMapper.queryListByParamPlus(goods,orderBy,order);
    }

    @Override
    public Goods queryByIdPlus(Integer id) {
        return goodsMapper.queryByIdPlus(id);
    }

    @Override
    @Transactional
    public void updateDeleteMany(List<Integer> ids) {
        for(int a=0;a<ids.size();a++){
            Goods g = new Goods();
            g.setIsDelete(0);
            g.setId(ids.get(a));
            updateDelete(g);
        }
    }

    @Override
    public void addOrEdit(Goods goods) {
        if(goods.getId()==null){
            saveNoNull(goods);
        }else{
            updateNoNull(goods);
        }
    }
}
